package playground.fs.rnkrsoft;

import java.io.BufferedReader;
import java.io.IOException;

/**
 * Created by test on 2020/3/5.
 * 字符串查找器
 */
public class StringFinderImpl implements StringFinder{
    @Override
    public FindTaskResult find(BufferedReader reader, String searchStr) throws IOException {
        FindTaskResult taskResult = new FindTaskResult();
        try {
            String line = null;
            //逐行读取内容并判断是否未要查找字符串开始
            while ((line = reader.readLine()) != null){
                if (line.contains(searchStr)){
                    taskResult.add(line);
                }
            }
        }finally {
            if (reader != null){
                reader.close();
            }
        }
        return taskResult;
    }
}